﻿/*
Copyright (c) 2010 Lance Ward
This software is licensed under the MIT license, except where otherwise noted.
For complete license details, refer to license.txt
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace ADNLib
{
	public enum MotionType
	{
        LineFill,   //object
        Size,       //object
        Rotation,   //object
        Order,      //object
        SwapGroup,  //object
        Morph,      //object
        MorphPath,  //object
        FX,         //object
        MotionPath, //object
        CameraMotionPath,
        PointMotionPath,
        GroupMotionPath,
        None
    }

    [Serializable]
	public class Motion : Shape
	{
		//the new settings for the shape are set in the base class.
		private int startFrame = 1; 
		private int duration = 1;	//for now, specified in frames, may change later
		private ObjectPath mpath = null;
		private MotionType mtype = MotionType.None;
		private string motionName = String.Empty;

		public Motion() { }
		public Motion(MotionType mtype)
		{
			this.mtype = mtype;
			this.motionName = mtype.ToString();
		}

		[XmlElement]
		public int StartFrame
		{
			get { return startFrame; }
			set { startFrame = value; }
		}

		[XmlElement]
		public int Duration
		{
			get { return duration; }
			set { duration = value; }
		}

		[XmlElement]
		public ObjectPath MotionPath
		{
			get { return mpath; }
			set { mpath = value; }
		}

		[XmlElement]
		public MotionType MotionType
		{
			get { return mtype; }
			set { mtype = value; }
		}

		[XmlElement]
		public String MotionName
		{
			get { return motionName; }
			set { motionName = value; }
		}

        public override void Draw(Graphics g)
        {
            DrawGhost(g);
        }

        public override void DrawGhost(Graphics g)
        {
            if (Path.Points.Count > 1)
            {
                GraphicsPath gp = new GraphicsPath();
                gp.AddBeziers(this.Path.GetBezierPoints());
                Pen p = new Pen(Color.Fuchsia, 1.0f);

                g.DrawPath(p, gp);
            }
        }

        public override bool HitTest(Graphics g, PointF p)
        {
            GraphicsPath gp = new GraphicsPath();
            gp.AddBeziers(this.Path.GetBezierPoints());
            RectangleF rect = this.Bounds;

            if (gp.IsVisible(p)) { return true; }
            if (gp.IsOutlineVisible(p, this.LineColor.GetPen(this.Bounds, this.LineSettings.Width))) { return true; }

            return false;
        }
	}
}
